package com.glasses.business.fragment;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.glasses.business.R;
import com.glasses.business.adapter.OrderGoodsAdapter;
import com.glasses.business.base.AppBaseFragment;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/9
 * Version：1.0
 */

public class OrderDetailFragment extends AppBaseFragment {
    @InjectView(R.id.orderDetailName)
    TextView orderDetailName;
    @InjectView(R.id.orderDetailPhone)
    TextView orderDetailPhone;
    @InjectView(R.id.orderDetailAddr)
    TextView orderDetailAddr;
    @InjectView(R.id.orderDetailRecylerView)
    RecyclerView orderDetailRecylerView;
    @InjectView(R.id.cancelTv)
    TextView cancelTv;
    @InjectView(R.id.payTv)
    TextView payTv;

    @Override
    public int getRootViewId() {
        return R.layout.fragment_order_detail;
    }

    @Override
    public void setViews() {
        setTitleTv("订单详情");
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1,
                StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setOrientation(StaggeredGridLayoutManager.VERTICAL);
        orderDetailRecylerView.setLayoutManager(layoutManager);
        orderDetailRecylerView.setAdapter(new OrderGoodsAdapter(getActivity(), null));
        orderDetailRecylerView.addItemDecoration(new SpaceItemDecoration(2));
    }

    @Override
    public void initData() {

    }

    @Override
    public boolean mainTabShow() {
        return false;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @OnClick({R.id.cancelTv, R.id.payTv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cancelTv:
                break;
            case R.id.payTv:
                break;
        }
    }

    public class SpaceItemDecoration extends RecyclerView.ItemDecoration {

        private int space;

        public SpaceItemDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

            if (parent.getChildPosition(view) != 0) {
                outRect.bottom = space;
                outRect.top = space;
            }
        }
    }
}
